#include <algorithm>
#include <cstdio>
#include <queue>

const int N = 200005, mod = 1e9 + 7;
struct TreeNode {
  int dat, ls, rs;
} tr[N << 7];

struct Edge {
  int v, nxt, w;
} e[N << 1];

int n, m, cnt, tot, s, t, rt[N << 1], mul[N << 1], pre[N];
int e_cnt, heads[N];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void print(int x) {
  ++tot;
  if (x == s) return (void)(printf("%d\n%d\n%d ", tr[rt[t]].dat, tot, x));
  print(pre[x]);
  printf("%d ", x);
}

bool cmp(int x, int y, int l, int r) {
  if (l == r) return tr[x].dat > tr[y].dat;
  int mid = (l + r) >> 1;
  if (tr[tr[x].rs].dat == tr[tr[y].rs].dat)
    return cmp(tr[x].ls, tr[y].ls, l, mid);
  else
    return cmp(tr[x].rs, tr[y].rs, mid + 1, r);
}

struct Node {
  int id, root;
  Node(int _id, int _root) : id(_id), root(_root) {}
  inline bool operator<(const Node &rhs) const { return cmp(root, rhs.root, 0, N); }
};
std::priority_queue<Node> q;

inline void pushup(int x, int pos) {
  tr[x].dat = (tr[tr[x].ls].dat + 1ll * tr[tr[x].rs].dat * mul[pos] % mod) % mod;
}

bool modify(int &x, int y, int l, int r, int p) {
  tr[x = ++cnt] = tr[y];
  if (l == r) return tr[x].dat ^= 1, tr[y].dat;
  int mid = (l + r) >> 1;
  bool res;
  if (p <= mid) {
    res = modify(tr[x].ls, tr[y].ls, l, mid, p);
    if (res) res = modify(tr[x].rs, tr[y].rs, mid + 1, r, p);
  } else {
    res = modify(tr[x].rs, tr[y].rs, mid + 1, r, p);
  }
  pushup(x, mid - l + 1);
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1, u, v, x; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &x);
    add(u, v, x), add(v, u, x);
  }
  mul[0] = 1;
  for (int i = 1; i < N << 1; ++i) mul[i] = (1ll * mul[i - 1] << 1) % mod;
  scanf("%d%d", &s, &t);
  q.push(Node(s, rt[s]));
  while (!q.empty()) {
    Node u = q.top();
    q.pop();
    if (u.root != rt[u.id]) continue;
    if (u.id == t) return print(t), 0;
    for (int i = heads[u.id], v, tmp; i; i = e[i].nxt) {
      modify(tmp, rt[u.id], 0, N, e[i].w);
      if (!rt[v = e[i].v] || cmp(rt[v], tmp, 0, N)) {
        rt[v] = tmp;
        pre[v] = u.id;
        q.push(Node(v, rt[v]));
      }
    }
  }
  puts("-1");
  return 0;
}